package yawning.mew.bear;

import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class BerserkAction extends SimulationEventAction {
	BearThreatSimulator mState;
	double mCooldownExpireTime;

	BerserkAction(BearThreatSimulator state) {
		super(state.mSimEngine);
		mState = state;
		if (mState.mModel.mToon.getTalent(BearModel.BERSERK) == 0) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownExpireTime > mState.mSimEngine.getSimTime()) return SimulationAction.ACTION_FAIL;
		if (mState.mIsLogging) mState.mLog.log("Berserk\n");

		mNrBerserk++;
		mState.mMangleAction.onBerserk();

		schedule(mState.mModel.berserkBuffDuration);
		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.berserkCDDuration;
		mState.onPrimalMadnessGain();

		return 0.0;
	}

	@Override
	public void onExpire() {
		if (mState.mIsLogging) mState.mLog.log("Berserk Expiration\n");
		mState.onPrimalMadnessLoss();
	}

	int mNrBerserk = 0;
}